'''
对糖尿病人的数据进行数据分析
'''
#import相应的模块
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as  sns

#read data csv file
train = pd.read_csv('E:\【❤】CSDN_AI_CLASS\第五周\logistic回归作业\pima-indians-diabetes .csv')
print(train.head())
print("Train:", train.shape)
#查看数据的基本信息
print(train.info())
print(train.describe())
NaN_col_names = ["Glucose",
                 "BloodPressure",
                 "SkinThickness",
                 "Insulin", "BMI"]
print((train[NaN_col_names] <=  0).sum())

#查看变量与目标之间的关系
sns.countplot(train['Outcome'])
plt.xlabel('Diabetes')
plt.ylabel('Number of occurrences')
plt.show()

fig1 = plt.figure()
sns.countplot(train['Pregnancies'])
plt.xlabel('Number of pregnants')
plt.ylabel('Number of occurrences')
plt.show()

sns.countplot(x='Pregnancies', hue='Outcome',data=train)
plt.show()
#血浆葡萄糖浓度与Outcome的关系
fig2 = plt.figure()
sns.distplot(train.Glucose, kde=False)
plt.xlabel('Plasma_glucose_concentration')
plt.ylabel('Number of occurrences')
plt.show()
sns.violinplot(x='Outcome', y='Glucose',data=train, hue="Outcome")
plt.xlabel('Diabetes', fontsize=12)
plt.ylabel('Plasma_glucose_concentration', fontsize=12)
plt.show()
#血压与Outcome的关系
fig3 = plt.figure()
sns.distplot(train.BloodPressure, kde=False)
plt.xlabel('blood pressure')
plt.ylabel('frequency')
plt.show()

sns.violinplot(x='Outcome', y='BloodPressure', data=train, hue="Outcome")
plt.xlabel('Diabetes', fontsize=12)
plt.ylabel('blood pressure', fontsize=12)
plt.show()
#三头肌皮褶厚度（单位：mm）与Outcome的关系
fig4 = plt.figure()
sns.distplot(train.SkinThickness, kde=False)
plt.xlabel('SkinThickness')
plt.ylabel('Frequency')
plt.show()
sns.violinplot(x='Outcome', y='SkinThickness', data=train, hue="Outcome")
plt.xlabel('Diabetes', fontsize=12)
plt.ylabel('SkinThickness', fontsize=12)
plt.show()
#餐后血清胰岛素（单位:mm）与Outcome的关系
fig5 = plt.figure()
sns.distplot(train.Insulin, kde=False)
plt.xlabel('serum insulin')
plt.ylabel('frequency')
plt.show()
sns.violinplot(x='Outcome', y='Insulin', data=train, Hue="Outcome")
plt.xlabel('Diabetes', fontsize=12)
plt.ylabel('Insulin', fontsize=12)
plt.show()
#体重指数（体重（公斤）/ 身高（米）^2）BMI与Outcome的关系
fig6 = plt.figure()
sns.distplot(train.BMI, kde=False)
plt.xlabel('BMI')
plt.ylabel('frequency')
plt.show()

sns.violinplot(x='Outcome', y='BMI', data=train, Hue="Outcome")
plt.xlabel('Diabetes', fontsize=12)
plt.ylabel('BMI', fontsize=12)
plt.show()
#BMI=0
BMIDF = train.groupby(['BMI', 'Outcome'])['BMI'].count().unstack('Outcome').fillna(0)
BMIDF[[0, 1]].plot(kind='bar', stacked=True)
plt.show()
#糖尿病家系作用与Outcome的关系
fig7 = plt.figure()
sns.distplot(train.DiabetesPedigreeFunction, kde=False)
plt.xlabel('DiabetesPedigreeFunction')
plt.ylabel('Outcome')
plt.show()
DF = train.groupby(['DiabetesPedigreeFunction', 'Outcome'])['DiabetesPedigreeFunction'].count().unstack('Outcome').fillna(0)
DF[[0, 1]].plot(kind='bar', stacked=True)
plt.show()
#年龄与Outcome的关系
fig8 = plt.figure()
sns.distplot(train.Age, kde=False)
plt.xlabel('Age')
plt.ylabel('Outcome')
plt.show()
AgeDF = train.groupby(['Age', 'Outcome'])['Age'].count().unstack('Outcome').fillna(0)
AgeDF[[0, 1]].plot(kind='bar', stacked=True)
plt.show()
#特征时间的相关性
data_corr = train.corr().abs()
plt.subplots(figsize=(13, 9))
sns.heatmap(data_corr, annot=True)
plt.show()

for feature in train.columns:
    sns.distplot(train[feature], kde=False)
    plt.show()